<!--
 * @Description: 网址库编辑
 * @Author: hanyu
 * @Date: 2022-03-16 10:24:25
 * @LastEditTime: 2022-03-16 15:15:33
 * @LastEditors: hanyu
-->
<template>
    <div class=''>
        <Form label-colon ref="mForm" :model="sendParams" :label-width="100" style="text-align:left">
            <FormItem label="页面网址标示" prop="website_label">
                <Input class="input-box" v-model="sendParams.website_label"></Input>
            </FormItem>
            <FormItem label="链接" prop="website_link">
                <Input class="input-box" v-model="sendParams.website_link"></Input>
            </FormItem>
            <FormItem label="抓取时间" prop="grab_time">
                <!-- <Input class="input-box" v-model="sendParams.grab_time"></Input> -->
                <DatePicker type="datetime" v-model="sendParams.grab_time" placeholder="选择日期" style="width: 200px"></DatePicker>
            </FormItem>
            <FormItem label="快照地址" prop="snapshot_address">
                <Input class="input-box" v-model="sendParams.snapshot_address"></Input>
            </FormItem>
            <FormItem label="响应代码" prop="response_code">
                <!-- <Input class="input-box" v-model="sendParams.response_code"></Input> -->
                <RadioGroup v-model="sendParams.response_code">
                    <Radio label="1">
                        <span>待爬</span>
                    </Radio>
                    <Radio label="200">
                        <span>正常</span>
                    </Radio>
                    <Radio label="2">
                        <span>页面已删除</span>
                    </Radio>
                    <Radio label="3">
                        <span>重定向</span>
                    </Radio>
                </RadioGroup>
            </FormItem>
            <FormItem label="所属网站id" prop="website_domain_id">
                <Input class="input-box" v-model="sendParams.website_domain_id"></Input>
            </FormItem>
        </Form>
        <Row class="flex-j-center">
            <Button type="primary" @click="onSubmit" style="margin-right: 50px;width: 100px">确定</Button>
            <Button @click="onCancel" style="width: 100px">取消</Button>
        </Row>
    </div>
</template>

<script>
import moment from 'moment'
import {
  allApi
} from '@/api/allApi';
export default {
  props: {
    value: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  watch: {
    value: {
      handler(e) {
        if (e) {
          this.sendParams = {
            website_lib_id: e.id,
            ...e,
            grab_time: moment(e.grab_time * 1000).format('YYYY-MM-DD hh:mm'),
          }
        }
      },
      immediate: true
    }
  },
  data() {
    //这里存放数据
    return {
      sendParams: {
        website_lib_id: null, // 网址库id
        website_label: null, // 网址标示
        website_link: null, // 网址库链接
        grab_time: null, // 抓取时间
        snapshot_address: null, // 快照地址
        response_code: null, // 响应代码
        website_domain_id: null, // 所属网站id
      }
    };
  },
  //方法集合
  methods: {
    async onSubmit() {
      this.$refs.mForm.validate(async valid => {
        if (valid) {
          try {
            this.$Spin.show();
            await allApi.websiteEditLib(this.sendParams)
            this.$Message.success('修改成功')
            this.onCancel()
          } catch (error) {
            console.log(error);
          }
          this.$Spin.hide()
        }
      })
    },
    //   关闭
    onCancel() {
      this.$emit('updatePage')
    }
  },
}
</script>
<style lang='less' scoped>
.input-box {
  width: 800px;
}
</style>